﻿@inject IHttpService _httpService



@inject NavigationManager NavigationManager

@if (isReady)
{
    <div class="rounded div-shadow bg-opacity p-3 @(IsNormalScreen?" h-100":"mb-3")" @onclick="OnDetails" style="cursor:pointer;">
        <div class="a-font-color h-100" style="display:flex;align-items: center;">
            <div style="display: flex;align-items: center;">
                <div class="swal2-icon m-0 me-1 @("border-"+color)" style="height: 3em; width: 3em; display: flex;align-items: center;">
                    <div class="@("text-"+color)">@Model.Grade.ToString("0.0")</div>
                </div>
            </div>
            <div class="comment-tx-div" style="height: 3.5em;">
                <div class="new-row-warp no-margin">
                    <div class="@("comment-tag me-2 bg-"+color)">@Model.Level.GetDisplayName()</div>
                    <div class="comment-username me-2">@("超过全站 "+Model.VictoryPercentage.ToString("0.0")+"% 的词条")</div>
                    <div class="comment-username" style="color:gray;">@(Model.LastEditTime.ToTimeFromNowString()+"编辑")</div>
                </div>
                <div class="comment-time">@("有"+Model.DefectCount+"个项目待完善，总计"+Model.EditCount+"次编辑")</div>
            </div>
        </div>
    </div>
}
<EntryPerfectionCheckListTip @ref="entryPerfectionCheckListTip"/>


@code {
    [Parameter]
    public int EntryId { get; set; }

    [Parameter]
    public bool IsNormalScreen { get; set; }

    EntryPerfectionCheckListTip entryPerfectionCheckListTip;
    public PerfectionInforTipViewModel Model { get; set; } = new PerfectionInforTipViewModel();

    bool isReady = false;

    string color = "success";
    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    protected override async Task OnInitializedAsync()
    {
        try
        {
            Model = await _httpService.GetAsync<PerfectionInforTipViewModel>("api/perfections/GetEntryPerfection/" + EntryId);
            color = ToolHelper.GetEntryPerfectionLevelColor(Model.Level);
            isReady = true;
            StateHasChanged();
        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取词条完善度信息失败");
        }
    }

    public async Task OnDetails()
    {
        if(entryPerfectionCheckListTip!=null)
        {
            await entryPerfectionCheckListTip.Refresh(true, Model.Id);
        }
    }
}
